package cn.weiron.fun.infrastructure.dictionary;

import java.util.Optional;

/**
 * 领域模型：字典
 */
public class Dictionary {
    /**
     * 复制一个新的字典对象
     */
    public static Dictionary copy(Dictionary other) {
        return (new Dictionary())
                .setCode(other.getCode())
                .setLabel(other.getLabel())
                .setGroup(other.getGroup())
                .setDescription(other.getDescription())
                .setExtend(other.getExtend())
                ;
    }

    /**
     * 字典编码
     */
    private String code;

    /**
     * 自定对应的标识内容
     */
    private String label;

    /**
     * 字典分组
     */
    private DictionaryGroup group;

    /**
     * 字典说明
     */
    private String description;

    /**
     * 字典扩展信息，用于自定义配置
     */
    private String extend;

    public String getCode() {
        return code;
    }

    public Dictionary setCode(String code) {
        this.code = code;
        return this;
    }

    public String getLabel() {
        return label;
    }

    public Dictionary setLabel(String label) {
        this.label = label;
        return this;
    }

    public DictionaryGroup getGroup() {
        return group;
    }

    public Dictionary setGroup(DictionaryGroup group) {
        this.group = group;
        return this;
    }

    public String getDescription() {
        return description;
    }

    public Dictionary setDescription(String description) {
        this.description = description;
        return this;
    }

    public String getExtend() {
        return extend;
    }

    public int getExtendInteger() {
        return Optional.ofNullable(extend).map(Integer::parseInt).orElse(0);
    }

    public Dictionary setExtend(String extend) {
        this.extend = extend;
        return this;
    }
}